I was a bit surprised to find myself writing this....
# community-support
r
I was a bit surprised to find myself writing this... is it because it's a dreadful idea?
Copy code
fun Test.envVarInput(envVar: String) {
  val value = providers.environmentVariable(envVar)
  inputs.property(envVar, value).optional(true)
  doFirst {
    val dbTypeResolved = value.orNull
    if (dbTypeResolved != null) {
      environment(envVar, dbTypeResolved)
    } else {
      environment.remove(envVar)
    }
  }
}

tasks.test {
  envVarInput("ENV_VAR_READ_BY_TESTS")
}
p
You could use an anonymous object instead, because environment is a MapString, Object and at execution time, the value will be retrieved by calling toString, but you still need the input declaration to wire the env as input.
I don't know why environment is not @Input in the first place but Internal
With Gradle 10, this hack won't be needed anymore
r
Cool, thanks